﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NailManager.DTO;
using System.Data.OleDb;
using System.Data;
using System.Collections;

namespace NailManager.DAO
{
    public class TicketGiftCardDAO : DataProvider
    {
        public ArrayList getList()
        {
            connect();
            ArrayList arr;
            try
            {
                string query = "SELECT * FROM TICKETGIFTCARD";
                adapter = new OleDbDataAdapter(query, connection);
                DataSet dataset = new DataSet();
                adapter.Fill(dataset);
                arr = ConvertDataSetToArrayList(dataset);

            }
            catch (Exception ex)
            {
                arr = new ArrayList();
            }
            return arr;
        }

        public ArrayList getList(string condition)
        {
            connect();
            ArrayList arr;
            try
            {
                string query = "SELECT * FROM TICKETGIFTCARD" + condition;
                adapter = new OleDbDataAdapter(query, connection);
                DataSet dataset = new DataSet();
                adapter.Fill(dataset);
                arr = ConvertDataSetToArrayList(dataset);

            }
            catch (Exception ex)
            {
                arr = new ArrayList();
            }
            return arr;
        }

        public void insert(TicketGiftCard info)
        {
            try
            {
                string insertCommand = "";
                OleDbParameter parameter = new OleDbParameter("@CreateDate", OleDbType.DBDate);
                parameter.Value = info.CreateDate;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@CusID", OleDbType.Integer);
                parameter.Value = info.CusID;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@PromotionID", OleDbType.Integer);
                parameter.Value = info.PromotionID;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@Total", OleDbType.Double);
                parameter.Value = info.Total;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@UserID", OleDbType.VarChar);
                parameter.Value = info.UserID;
                command.Parameters.Add(parameter);


                executeNonQuery(insertCommand);
                command.Parameters.Clear();
            }
            catch (Exception ex)
            {
                command.Parameters.Clear();
                return;
            }
        }

        public void update(TicketGiftCard info)
        {
            try
            {
                string updateCommand = "";
                OleDbParameter parameter = new OleDbParameter("@TicketID", OleDbType.Integer);
                parameter.Value = info.TicketID;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@CreateDate", OleDbType.DBDate);
                parameter.Value = info.CreateDate;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@CusID", OleDbType.Integer);
                parameter.Value = info.CusID;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@PromotionID", OleDbType.Integer);
                parameter.Value = info.PromotionID;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@Total", OleDbType.Double);
                parameter.Value = info.Total;
                command.Parameters.Add(parameter);

                parameter = new OleDbParameter("@UserID", OleDbType.VarChar);
                parameter.Value = info.UserID;
                command.Parameters.Add(parameter);


                executeNonQuery(updateCommand);
                command.Parameters.Clear();
            }
            catch (Exception ex)
            {
                command.Parameters.Clear();
                return;
            }
        }

        public void delete(string id)
        {
            try
            {
                string deleteCommand = "";
                OleDbParameter parameter = new OleDbParameter("@TicketID", OleDbType.VarChar);
                parameter.Value = id;
                command.Parameters.Add(parameter);
                executeNonQuery(deleteCommand);
                command.Parameters.Clear();
            }
            catch (Exception ex)
            {
                command.Parameters.Clear();
                return;
            }
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            TicketGiftCard info = new TicketGiftCard();
            info.TicketID = int.Parse(dt.Rows[i]["TicketID"].ToString());

            return (object)info;
        }
    }
}
